package com.entrogy.service.impl;

import com.entrogy.bean.PositionEntity;
import com.entrogy.bean.TeacherBasicInfoEntity;
import com.entrogy.dao.PositionMapper;
import com.entrogy.dao.UserMapper;
import com.entrogy.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName PositionServiceImpl
 * @Description
 * @Author luoxingjiang
 * @Date 2019/9/20 0020 下午 5:16
 * @Version 1.0
 **/
@Service
public class PositionServiceImpl implements PositionService {

    @Autowired
    private PositionMapper positionMapper;

    @Override
    public Integer getIdByStaticPositionId(Integer staticPositionId, Integer schoolCode) {
        return positionMapper.getIdByStaticPositionId(staticPositionId, schoolCode);
    }

    @Override
    public TeacherBasicInfoEntity getClassLeader(Integer classId, Integer schoolCode) {
        return positionMapper.getClassLeader(classId, schoolCode);
    }

    @Override
    public TeacherBasicInfoEntity getGradeLeader(Integer gradeId, Integer schoolCode) {
        return positionMapper.getGradeLeader(gradeId, schoolCode);
    }

    @Override
    public boolean checkPosition(String teacherId, Integer positionId) {
        List<PositionEntity> positionList = positionMapper.listTeacherPosition(teacherId);
        boolean checkPosition = false;
        for (PositionEntity positionEntity : positionList) {
            if (positionId.equals(positionEntity.getSid())){
                checkPosition = true;
            }
        }
        return checkPosition;
    }

    @Override
    public List<Integer> listPositionId(String teacherId) {
        List<PositionEntity> positionList = positionMapper.listTeacherPosition(teacherId);
        List<Integer> positionIdList = new ArrayList<>();
        for (PositionEntity positionEntity : positionList) {
            positionIdList.add(positionEntity.getSid());
        }
        return positionIdList;
    }

    @Override
    public List<PositionEntity> listTeacherPosition(String teacherId) {
        return positionMapper.listTeacherPosition(teacherId);
    }

    @Override
    public boolean isNotPosition(String uid, List<Integer> positionIds) {
        List<PositionEntity> positionList = positionMapper.listTeacherPosition(uid);
        List<Integer> positionIdList = new ArrayList<>();
        for (PositionEntity positionEntity : positionList) {
            positionIdList.add(positionEntity.getSid());
        }
        for (Integer positionId : positionIdList) {
            if (!positionIds.contains(positionId)){
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean InsertUserPositionInfos(String teacherId, List<PositionEntity> positionList) {
        return positionMapper.InsertUserPositionInfos(teacherId, positionList) == positionList.size();
    }

    @Override
    public PositionEntity getPositionByPid(Integer schoolCode, int pId) {
        return positionMapper.getPositionByPid(schoolCode, pId);
    }


}
